package org.opens.mybatisplus.service;

import org.opens.mybatisplus.entity.BasParamEntity;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;

/**
 * 功能:
 *
 * @author zym
 * @Date 2022/1/10 17:36
 */
public interface RedisService {

    /**
     * 功能: 设置缓存
     */
    @Cacheable(key = "#hosNum+'-'+#name", cacheNames = "basParam")
    public BasParamEntity findByName(String hosNum, String name);

    @Cacheable(key = "#hosNum+'-'+#name", cacheNames = "basParam1")
    public BasParamEntity findByName2(String hosNum, String name);

    /**
     * 功能: 清空缓存.
     * 备注:
     * 1. @Caching注解用于清空多个缓存key;
     * 2. @CacheEvict的allEntries设置为true之后, 将会删除basParam对应的所有缓存, 忽略剩余的key.
     * 3. 也可以使用@CchePut来是实现, 但是没有@CacheEvict简单.
     * @param id    主键
     */
    @Caching(evict = {
            @CacheEvict(value = "basParam", allEntries = true),
            @CacheEvict(value = "basParam1", allEntries = true)
    })
    public void deleteById(String id);

}
